<?php

if (!defined('access')){
	die ('Direct access Denied!');
} else {

	define('libnews',true);

	class News {
	
		public function __construct(){}
	
		public function getNews($from,$to){
			$news = array();
			$data = execQuery("SELECT news.newsid,news.newsdate,news.newstitle,news.newstext,membres.username FROM membres INNER JOIN news ON news.membres_userid = membres.userid LIMIT ". $from .",". $to);
		
			while ($billet = $data->fetch()){
				$news[] = array('newsid' => $billet['newsid'],
								'newsdate' => $billet['newsdate'],
								'newstitle' => $this->bbtranslate($billet['newstitle']),
								'newstext' => $this->bbtranslate($billet['newstext']),
								'username' => $billet['username']);
			}		
			return $news;
		}
	
		public function getBillet($id){
			$data = execQuery("SELECT news.newsid,news.newsdate,news.newstitle,news.newstext, membres.username FROM membres INNER JOIN news ON news.membres_userid = membres.userid WHERE newsid = '". $id ."'")->fetch();
			$billet = array('newsid' => $data['newsid'],
							'newsdate' => $data['newsdate'],
							'newstitle' => $this->bbtranslate($data['newstitle']),
							'newstext' => $this->bbtranslate($data['newstext']),
							'username' => $data['username']);
						
			return $billet;
		}
	
		private function bbtranslate($text){
			$bbc = array('[b]','[/b]','[u]','[/u]','[s]','[/s]','[img]','[/img]');
			$html = array('<b>','</b>','<u>','</u>','<s>','</s>','<img src="','"/>');
		
			$text = str_replace($bbc,$html,$text);
		
			return $text;
		}
	}
}
?>